package com.sviet.game.tetriswindow;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

import com.google.ads.AdRequest;
import com.google.ads.AdView;
import com.google.ads.mediation.admob.AdMobAdapterExtras;
import com.sviet.game.tetriswindow.dialog.AboutDialog;
import com.sviet.game.tetriswindow.dialog.ControlModeDialog;
import com.sviet.game.tetriswindow.dialog.HighScoreDialog;
import com.sviet.game.tetriswindow.listener.ToastAdListener;
import com.sviet.game.tetriswindow.util.Constants;

public class MenuActivity extends Activity implements OnClickListener {

	private String TAG = MenuActivity.class.getSimpleName();
	private Button bt_resume;
	private Button bt_high_score;
	private Button bt_setting;
	private Button bt_about;
	private Button bt_exit;
	private AdView ad_view;
//	private ImageButton imgbtn_close_ad;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_menu);

		Log.v(TAG, "onCreate");
		bt_resume = (Button) findViewById(R.id.menu_bt_resume);
		bt_resume.setOnClickListener(this);
		bt_high_score = (Button) findViewById(R.id.menu_bt_high_score);
		bt_high_score.setOnClickListener(this);
		bt_setting = (Button) findViewById(R.id.menu_bt_control_mode);
		bt_setting.setOnClickListener(this);
		bt_about = (Button) findViewById(R.id.menu_bt_about);
		bt_about.setOnClickListener(this);
		bt_exit = (Button) findViewById(R.id.menu_bt_exit);
		bt_exit.setOnClickListener(this);

		ad_view = (AdView) findViewById(R.id.menu_ad_view);
		// ad_view.setAdUnitId(getResources().getString(R.string.ad_unit_id));
		// ad_view.setAdSize(AdSize.BANNER);
		ad_view.setAdListener(new ToastAdListener(this));
		AdRequest adRequest = new AdRequest();

		// AdMobAdapterExtras extras = new AdMobAdapterExtras()
		// .addExtra("color_bg", "AAAAFF")
		// .addExtra("color_bg_top", "FFFFFF")
		// .addExtra("color_border", "FFFFFF")
		// .addExtra("color_link", "000080")
		// .addExtra("color_text", "808080")
		// .addExtra("color_url", "008000");
		AdMobAdapterExtras extras = new AdMobAdapterExtras()
				.addExtra("color_bg", "0099FF")
				.addExtra("color_bg_top", "FFFFFF")
				.addExtra("color_border", "FFFFFF")
				.addExtra("color_link", "000080")
				.addExtra("color_text", "FFFFFF")
				.addExtra("color_url", "008000");

		adRequest.setNetworkExtras(extras);
		ad_view.loadAd(adRequest);

//		imgbtn_close_ad = (ImageButton) findViewById(R.id.menu_imgbtn_close_ad);
//		imgbtn_close_ad.setOnClickListener(this);
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		// TODO Auto-generated method stub
		super.onActivityResult(requestCode, resultCode, data);

		if (requestCode == Constants.EXITAPP) {
			if (resultCode == RESULT_OK) {
				finish();
			}
		}
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		if (v.getId() == R.id.menu_bt_resume) {
			finish();
		} else if (v.getId() == R.id.menu_bt_high_score) {
			HighScoreDialog dialog = new HighScoreDialog(this);
			dialog.show();
		} else if (v.getId() == R.id.menu_bt_control_mode) {
			ControlModeDialog dialog = new ControlModeDialog(this);
			dialog.show();
		} else if (v.getId() == R.id.menu_bt_about) {
			AboutDialog dialog = new AboutDialog(this);
			dialog.show();
		} else if (v.getId() == R.id.menu_bt_exit) {
			// Exit app
			Intent intent = new Intent();
			setResult(RESULT_OK, intent);
			finish();
		} else if (v.getId() == R.id.menu_imgbtn_close_ad) {
//			ad_view.setVisibility(View.GONE);
//			imgbtn_close_ad.setVisibility(View.GONE);
		}
	}
}
